package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.server.manger.activity.foxcard.FoxCardMgr;

import java.util.ArrayList;
import java.util.List;

public class FoxCardRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        FoxCardConfig config = FoxCardMgr.getConfig();
        if (config != null) {
            int powerGoodsId = config.getLotteryPowerId();
            long recycleTime = config.getActivityInfo().getEndTime() * 1000L + 300 * 1000;//领奖期回收

            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(powerGoodsId));
            paramList.add(String.valueOf(config.getScoreItemId()));
            paramList.add("1");
            paramList.add(config.getActivityInfo().getActivityName());

            ActivityItemRecycleMgr.addRecycleItemData(powerGoodsId, config.getActivityInfo().getType(), 1, recycleTime, paramList);

            int startGameItemId = config.getStartGameItemId();
            ActivityItemRecycleMgr.addRecycleItemData(startGameItemId, config.getActivityInfo().getType(), 2, recycleTime, new ArrayList<>());
        }

    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.FoxCard.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int recycleType = data.getRecycleType();
        if (recycleType == 1) {
            item2Score(userId, data);
        }else if (recycleType == 2) {
            UserBagItem userBagItem = getUserBagItem(userId, data.getItemId());
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }
}
